package cloudInformation.service.impl;

import cloudEntity.dto.news.SmartNewsInsertDTO;
import cloudEntity.dto.news.SmartNewsUpdateDTO;
import cloudEntity.vo.PageBeanVO;
import cloudEntity.vo.news.SmartNewsVO;
import cloudInformation.mapper.SmartNewsMapper;
import cloudInformation.service.SmartNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: Smart School
 * @ClassName SmartNewsServiceImpl
 * @description:
 * @author: 陈智博
 * @create: 2025-04-14 08:31
 * @Version 1.0
 **/
@Service
public class SmartNewsServiceImpl implements SmartNewsService {

    @Autowired
    private SmartNewsMapper smartNewsMapper;

    @Override
    public PageBeanVO<SmartNewsVO> GetSmartNews(Integer query, Integer pageNum, Integer pageSize) {
        Integer pageBean = (pageNum - 1) * pageSize;
        Integer countSize = smartNewsMapper.GetNewsCount(query);
        List<SmartNewsVO> smartNewsDTOS = smartNewsMapper.GetNewsByType(query,pageBean,pageSize);
        return new PageBeanVO<>(pageNum,pageSize,countSize,smartNewsDTOS);
    }

    @Override
    public Integer UpdateSmartNews(SmartNewsUpdateDTO smartNewsUpdateDTO) {
        return smartNewsMapper.UpdateNewsDetails(
                smartNewsUpdateDTO.getSysNewsId(),
                smartNewsUpdateDTO.getSysNewsDescription(),
                smartNewsUpdateDTO.getSysNewsPic());
    }

    @Override
    public Integer deleteSmartNews(Long ids) {
        return smartNewsMapper.deleteNewsByIds(ids);
    }

    @Override
    public List<SmartNewsVO> SelectSmartNewsByType(Integer type) {
       return smartNewsMapper.GetNewsDataExport(type);
    }

    @Override
    public Integer InsertNews(SmartNewsInsertDTO insertDTO) {
       return smartNewsMapper.InsertNewsData(
                insertDTO.getSysNewsTitle(),
                insertDTO.getSysNewsDescription(),
                insertDTO.getSysNewsPic(),
                insertDTO.getSysNewsType());
    }

}
